<?php

class DefaultSort extends CActiveRecordBehavior {
	
	public function beforeFind($event) {
		$ownerCriteria = $this->getOwner()->getDbCriteria();
		$alias = $ownerCriteria->alias ? $ownerCriteria->alias : 't';
		$pk = $this->getOwner()->getMetadata()->tableSchema->primaryKey;
		if(is_string($pk)) {
			$criteria = new CDbCriteria(array(
				'order' => "`{$alias}`.`{$pk}` DESC",
			));
			$ownerCriteria->mergeWith($criteria);
		}
	}
}

?>